<?php

namespace app\admin\model\usermanage;

use think\Model;
use traits\model\SoftDelete;


class Users extends Model
{

    use SoftDelete;
    

    // 表名
    protected $name = 'users';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        //'time_text',
        //'register_auth_time_text',
        //'deduction_pv_time_text'
    ];
    


    public function getTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['time']) ? $data['time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getRegisterAuthTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['register_auth_time']) ? $data['register_auth_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getDeductionPvTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['deduction_pv_time']) ? $data['deduction_pv_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    protected function setTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setRegisterAuthTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setDeductionPvTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
